home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / admin / admin-v1.000 / admin-v1 / lbu < prev    next >
Text File  |  1995-05-20  |  40KB  |  1,282 lines

  1. #!/bin/sh
  2. # *************************************************************************
  3. # *                                                                       *
  4. # * Menu-driven backup script using tar. Author Jonathan Warburton-Brown  *
  5. # *                                                                       *
  6. # * This utility is freely distributable under the terms of the GNU GPL.  *
  7. # *                                                                       *
  8. # *************************************************************************
  9. #
  10.  
  11. #
  12. # ------- UNCOMMENT THIS LINE IF YOUR CONSOLE TYPE (eg con80x25) IS NOT
  13. # ------- DEFINED IN THE TERMINFO DATABASE. NOTE MOST USERS OF LINUX USE
  14. # ------- con80x25 SO THIS HAS BEEN INCLUDED WITH THE DISTRIBUTION.
  15. # ------- Also con80x25 makes LBU look much prettier
  16.  
  17. # TERM=vt100 ; export TERM
  18.  
  19. #
  20. # ------- SET THIS VARIABLE TO yes IF ONLY ROOT IS TO BE ALLOWED TO RUN LBU
  21. #
  22. TVERSION="Linux Business Systems V1.2                    `date`"
  23. lbu_root_only=no
  24.  
  25. #
  26. # ------- CHANGE THIS IF YOU CHANGE THE NAME OF THE BACKUP SCRIPT
  27. #
  28.  
  29. lbu_program_name=lbu
  30.  
  31. #
  32. # ------- CHANGE THIS TO POINT TO THE LBU LIBRARY & HELP FILES
  33. #
  34.  
  35. lbu_dir=/usr/lib/LBU
  36.  
  37. #
  38. # ------- PER USER TEMPORARY STORAGE FILE
  39. #
  40.  
  41. lbu_tmpfile="/tmp/$LOGNAME"lbu_sel
  42.  
  43. # *************************************************************************
  44. # *                        L.B.U Processing sub-routines                  *
  45. # *************************************************************************
  46.  
  47.  
  48. lbu_proceed() {
  49.     lbu_loop1=1
  50.     while [ $lbu_loop1 = 1 ]; do
  51.     dialog --title "$lbu_title" \
  52.     --backtitle " $TVERSION" \
  53.     --menu " " 20 74 14 \
  54.     "Device"   "Select bkup/rstr/cmpr device.   ($lbu_dsply_dev)"     \
  55.     "File/Dir" "Select data to bkup/rstr/cmpr.  ($lbu_dsply_dfl)"     \
  56.     "Options"  "(Un)Set run-time option flags."            \
  57.     "Begin"       "Start the backup procedure."            \
  58.     "Schedule" "Schedule backup/restore for later."            \
  59.     "Restore"  "Restore previous backup."                \
  60.     "Look"     "Look at status screen."                \
  61.     "Compare"  "Check for differences between backup & file-system."\
  62.     "Inspect"  "Look at latest bkup/rstr/cmpr log."            \
  63.     "View"       "View the contents of a previous backup."        \
  64.     "Write"    "Save currently selected details to disk."        \
  65.     "Exclude"  "Create/Modify an exclusion list"            \
  66.     "Help"     "Help regarding the L.B.U."                 \
  67.     "Quit"     "Quit Linux Backup Utility."                2> $lbu_tmpfile
  68.  
  69. # ------- Get selection and act accordingly
  70.  
  71.     if [ $? = 1 -o $? = 255 ]; then
  72.         rm $lbu_tmpfile
  73.         lbu_msgtyp="Informational" ; lbu_msgtxt="Operation cancelled."
  74.         lbu_hgt=5 ; lbu_wth=34
  75.         lbu_message
  76.         reset ; clear
  77.         exit
  78.     fi
  79.  
  80.     lbu_chc=`cat $lbu_tmpfile`
  81.     rm -f $lbu_tmpfile
  82.     case $lbu_chc in
  83.         Device)     lbu_devsel;;
  84.         File/Dir)    lbu_fstsel;;
  85.         Options)    lbu_options;;
  86.         Begin)        lbu_begin;;
  87.         Schedule)    lbu_schedule;;
  88.         Restore)    lbu_restore;;
  89.         Look)        lbu_look;;
  90.         Compare)    lbu_comp;;
  91.         Inspect)    lbu_inspect;;
  92.         View)        lbu_view;;
  93.         Write)             lbu_write;;
  94.         Exclude)    lbu_exclude;;
  95.         Help)
  96.                 lbu_hlpfile="$lbu_dir/lbu_help1"
  97.                 lbu_help
  98.                 ;;
  99.  
  100.         Quit)        lbu_quit;;
  101.         *)        lbu_invent;;
  102.     esac
  103.     done
  104. }
  105.  
  106. # *********************************************************************
  107. # *             Backup device selection subroutine                    * 
  108. # *********************************************************************
  109.  
  110. lbu_devsel() {
  111.     lbu_loop2=1
  112.     lbu_devtype=""
  113.     lbu_dsply_dev=""
  114.     while [ $lbu_loop2 = 1 ]; do
  115.     lbu_devexist=yes
  116.     lbu_ext=$lbu_orig_ext
  117.     lbu_loop2=0
  118.     dialog --title "L.B.U device selection" --inputbox "Select backup/restore device (? for help)" 8 48 2> $lbu_tmpfile
  119.     lbu_device=`tr -s [*\ ] [?_] < $lbu_tmpfile`
  120.     rm -f $lbu_tmpfile
  121.  
  122. # ------- check for no input provided
  123.  
  124.       if [ -z "$lbu_device" ]; then
  125.         lbu_msgtyp="Error" ; lbu_msgtxt="No backup/restore device specified\n        Aborting"
  126.         lbu_hgt=6 ; lbu_wth=38
  127.         lbu_message
  128.         lbu_loop2=0
  129.     else
  130.  
  131. # ------- asking for help ?
  132.  
  133.         if [ $lbu_device = ? ]; then
  134.             lbu_hlpfile="$lbu_dir/lbu_help2"
  135.             lbu_help
  136.             lbu_loop2=1
  137.             lbu_dsply_dev="" ; lbu_device=""
  138.         else
  139.  
  140. # ------- validate that either a block device or a filename is entered
  141.  
  142.             if [ -a $lbu_device ]; then
  143.                 lbu_devtype=`ls -ld $lbu_device | cut -c1`
  144.                 if [ $lbu_devtype = b ]; then
  145.                     lbu_ext=""
  146.                 fi
  147.                 if [ $lbu_devtype = c ]; then
  148.                     lbu_msgtyp="Warning" ; lbu_msgtxt="You have selected a character special\ndevice. Normally such a device is\nselected only if it is a tapedrive\nor similar stream device."
  149.                     lbu_hgt=8 ; lbu_wth=45
  150.                     lbu_message
  151.                     lbu_ext=""
  152.                 fi    
  153.  
  154.                 if [ $lbu_devtype = d ]; then
  155.                     lbu_msgtyp="Error" ; lbu_msgtxt="File specified is a directory.\nPlease specify a file or device."
  156.                     lbu_hgt=6 ; lbu_wth=40
  157.                     lbu_message
  158.                     lbu_loop2=1    
  159.                 fi
  160.  
  161.                 if [ $lbu_devtype = l ]; then
  162.                     lbu_msgtyp="Error" ; lbu_msgtxt="File specified is a link.\nPlease specify a file or device."
  163.                     lbu_hgt=6 ; lbu_wth=40
  164.                     lbu_message
  165.                     lbu_loop2=1    
  166.                 fi
  167.  
  168.             else
  169.                 if [ -a $lbu_device$lbu_ext ]; then
  170.                     lbu_msgtyp="Informational" ; lbu_msgtxt="The file $lbu_device$lbu_ext exists and \nis not a device file. If a BACKUP is being performed\nit will be overwritten. If this is not OK, reselect the device."
  171.                     lbu_hgt=7 ; lbu_wth=70
  172.                     lbu_message
  173.                 else
  174.                     touch $lbu_device$lbu_ext 2> /dev/null
  175.                     rm $lbu_device$lbu_ext 2> /dev/null
  176.                     if [ $? != 0 ]; then
  177.                         lbu_msgtyp="Error" ; lbu_msgtxt="Path to file $lbu_device$lbu_ext not present.\nPlease re-enter."
  178.                         lbu_hgt=6 ; lbu_wth=70
  179.                         lbu_message
  180.                         lbu_loop2=1
  181.                     else
  182.                         lbu_msgtyp="Warning" ; lbu_msgtxt="The file $lbu_device$lbu_ext does NOT exist.\nIf a BACKUP is being performed it will be created as\nan ordinary file.\nIf you are about to perform a RESTORE operation\nit will FAIL unless you specify an existing file or device."
  183.                         lbu_hgt=9 ; lbu_wth=70
  184.                         lbu_message
  185.                         lbu_devexist=no
  186.                     fi
  187.                 fi
  188.             fi
  189.         fi
  190.     fi
  191.  
  192.     if [ ! -z "$lbu_device" ]; then
  193.         lbu_device=$lbu_device$lbu_ext
  194.         lbu_dsply_dev=`echo $lbu_device | cut -c1-20`'...'
  195.     fi
  196.     done
  197. }
  198.  
  199. # ********************************************************************
  200. # *         Backup directory / file selection subroutine             *
  201. # ********************************************************************
  202.  
  203. lbu_fstsel() {
  204.     lbu_loop2=1
  205.     lbu_dirfil=""
  206.     lbu_dsply_dfl=""
  207.     while [ $lbu_loop2 = 1 ]; do
  208.         lbu_loop2=0
  209.         dialog --title "L.B.U directory / file selection" --inputbox "Enter a comma (,) separated list of dirs and/or files (? for help)" 8 77 2> $lbu_tmpfile
  210.         lbu_dirfil=`tr -s "[ ]" "[,]" < $lbu_tmpfile`
  211.         case $lbu_dirfil in
  212.             '')
  213.                 lbu_msgtyp="Warning" ; lbu_msgtxt="No dirs / files specified."
  214.                 lbu_hgt=5 ; lbu_wth=35
  215.                 lbu_message
  216.                 lbu_loop2=0
  217.                 ;;
  218.  
  219.             \*)    ;;
  220.  
  221.             \?)
  222.                 lbu_hlpfile="$lbu_dir/lbu_help3"
  223.                 lbu_help
  224.                 lbu_loop2=1
  225.                 ;;
  226.  
  227.             *)
  228.                 lbu_dirfil=$lbu_dirfil','
  229.                 echo $lbu_dirfil > $lbu_tmpfile
  230.                 lbu_loop3=1
  231.                 lbu_ctr=1
  232.                 while [ $lbu_loop3 = 1 ]; do
  233.                     lbu_field=`cut -f$lbu_ctr -d, < $lbu_tmpfile`
  234.                     case $lbu_field in
  235.                         $lbu_dirfil)    lbu_loop3=0;;
  236.                         *\**)        ;;
  237.                         *\?*)        ;;
  238.                         *)
  239.                         if [ ! -a $lbu_field ]; then
  240.                             lbu_msgtyp="Informational" ; lbu_msgtxt="One of the files or directories specified\ndoes not exist. If doing a BACKUP this will\ncause the Status Screen to show FAILURE\neven though existing files WILL have been\nbacked up. Be sure to check the logfile."
  241.                             lbu_hgt=9 ; lbu_wth=50
  242.                             lbu_message
  243.                             lbu_loop3=0
  244.                         fi;;
  245.                     esac
  246.                 lbu_ctr=`expr $lbu_ctr + 1`
  247.                 done;;
  248.         esac    
  249.     done
  250.     echo $lbu_dirfil > $lbu_tmpfile
  251.     case $lbu_dirfil in
  252.     '')
  253.         rm -f $lbu_tmpfile
  254.         ;;
  255.     *)
  256.         lbu_dirfil=`tr "[,]" "[ ]" <$lbu_tmpfile`
  257.         lbu_dsply_dfl=`echo $lbu_dirfil | cut -c1-20`'...'
  258.         ;;
  259.     esac
  260. }
  261.  
  262. # **********************************************************************
  263. # *                (Un)Set runtime options                             *
  264. # **********************************************************************
  265.     
  266. lbu_options() {
  267.  
  268.     lbu_loop2=1
  269.     while [ $lbu_loop2 = 1 ]; do
  270.         dialog --title "$lbu_title" \
  271.         --backtitle "$TVERSION"\
  272.         --menu "\n            **** RUNTIME OPTIONS ****\n" 20 74 14 \
  273.         "Done"     "Return to Main Menu."                    \
  274.         "Multi"    "Multi-volume archive.                  ($lbu_dsply_multi)"     \
  275.         "Absolute" "Preserve absolute pathnames.           ($lbu_dsply_absol)"     \
  276.         "Inform"   "Mail log file to self.                 ($lbu_dsply_mail)"    \
  277.         "Block"       "Specify Block-size.                    ($lbu_dsply_blcks)"    \
  278.         "Perms"       "Preserve permissions.                  ($lbu_dsply_perms)"    \
  279.         "Owner"       "Preserve ownership.                    ($lbu_dsply_owner)"    \
  280.         "Totals"   "Log total byte-count.                  ($lbu_dsply_total)"    \
  281.         "Verbose"  "Verbose logging.                       ($lbu_dsply_vbose)"    \
  282.         "Compress" "Select compression type.               ($lbu_dsply_cmprs)"    \
  283.         "Exclude"  "Enable/Disable file exclusion          ($lbu_dsply_excl)"    \
  284.         "Help"     "Help regarding Options"                    2> $lbu_tmpfile
  285.  
  286. # ------- Get the selection made and act accordingly
  287.  
  288.         if [ $? = 1 -o $? = 255 ]; then
  289.             rm $lbu_tmpfile
  290.             lbu_msgtyp="Informational" ; lbu_msgtxt="Operation cancelled."
  291.             lbu_hgt=5 ; lbu_wth=34
  292.             lbu_message
  293.             lbu_loop2=0
  294.         else
  295.  
  296.             lbu_sel=`cat $lbu_tmpfile`
  297.             rm -f $lbu_tmpfile
  298.  
  299.             case $lbu_sel in
  300.             Multi)         
  301.                 if [ $lbu_dsply_multi = yes ]; then
  302.                     lbu_dsply_multi=no ; lbu_multi=""
  303.                 else
  304.                     lbu_dsply_multi=yes ; lbu_multi="-M"
  305.                     if [ $lbu_cmprs != "" ]; then
  306.                         lbu_dsply_cmprs="none" ; lbu_cmprs=''
  307.                         lbu_device="" ; lbu_dsply_dev="" ; lbu_orig_ext=".tar"
  308.                         lbu_msgtyp="Informational" ; lbu_msgtxt="Cannot have compressed multi-volume archives.\nCompression parameter set to 'none'.\nYOU MUST RE-SELECT THE BACKUP DEVICE."
  309.                         lbu_hgt=7 ; lbu_wth=55
  310.                         lbu_message
  311.                     fi
  312.                 fi
  313.                 ;;
  314.             Absolute)
  315.                 if [ $lbu_dsply_absol = yes ]; then 
  316.                     lbu_dsply_absol=no  ; lbu_absol=""
  317.                 else
  318.                     lbu_dsply_absol=yes ; lbu_absol="P"
  319.                 fi
  320.                 ;;
  321.             Inform)
  322.                 if [ $lbu_dsply_mail = yes ]; then 
  323.                     lbu_dsply_mail=no  ; lbu_mail=no
  324.                 else
  325.                     lbu_dsply_mail=yes ; lbu_mail=yes
  326.                 fi
  327.                 ;;
  328.             Block)
  329.                 lbu_blocksize
  330.                 ;;
  331.             Perms)    
  332.                 if [ $lbu_dsply_perms = yes ]; then 
  333.                     lbu_dsply_perms=no  ; lbu_perms=""
  334.                 else
  335.                     lbu_dsply_perms=yes ; lbu_perms="p"
  336.                 fi
  337.                 ;;
  338.             Owner)
  339.                 if [ $lbu_dsply_owner = yes ]; then 
  340.                     lbu_dsply_owner=no  ; lbu_owner=""
  341.                 else
  342.                     lbu_dsply_owner=yes ; lbu_owner='--same-owner'
  343.                 fi
  344.                 ;;
  345.             Totals)
  346.                 if [ $lbu_dsply_total = yes ]; then 
  347.                     lbu_dsply_total=no  ; lbu_total=""
  348.                 else
  349.                     lbu_dsply_total=yes ; lbu_total='--totals'
  350.                 fi
  351.                 ;;
  352.             Verbose)
  353.                 if [ $lbu_dsply_vbose = yes ]; then 
  354.                     lbu_dsply_vbose=no  ; lbu_vbose=""
  355.                 else
  356.                     lbu_dsply_vbose=yes ; lbu_vbose="v"
  357.                 fi
  358.                 ;;
  359.             Compress)
  360.                 lbu_compress
  361.                 ;;
  362.             Exclude)
  363.                 if [ $lbu_dsply_excl = yes ]; then 
  364.                     lbu_dsply_excl=no  ; lbu_excl=""
  365.                 else
  366.                     lbu_dsply_excl=yes ; lbu_excl='-X $HOME/.lbu_exclude'
  367.                 fi
  368.                 ;;
  369.             Help)
  370.                 lbu_hlpfile="$lbu_dir/lbu_help4"
  371.                 lbu_help
  372.                 ;;
  373.             Done)
  374.                 lbu_loop2=0
  375.                 ;;
  376.             *)        lbu_invent
  377.                 ;;
  378.             esac
  379.         fi
  380.     done
  381. }
  382.  
  383. # *********************************************************************
  384. # *                   Select Blocksize sub-routine                    *
  385. # *********************************************************************
  386.  
  387. lbu_blocksize() {
  388.         dialog --title "Block-size selection" \
  389.         --backtitle "$TVERSION"\
  390.         --menu "" 14 45 7 \
  391.         "5"       "2,560  bytes per block."             \
  392.         "10"       "5,120  bytes per block."             \
  393.         "15"       "7,680  bytes per block."            \
  394.         "20"       "10,240 bytes per block. (default)"        \
  395.         "25"       "12,800 bytes per block."            \
  396.         "30"       "15,360 bytes per block."            \
  397.         "35"       "17,920 bytes per block."            2> $lbu_tmpfile
  398.  
  399. # ------- Get the selection made and act accordingly
  400.  
  401.         if [ $? = 1 -o $? = 255 ]; then
  402.             rm $lbu_tmpfile
  403.             lbu_msgtyp="Informational" ; lbu_msgtxt="Operation cancelled."
  404.             lbu_hgt=5 ; lbu_wth=34
  405.             lbu_message
  406.         else
  407.             lbu_dsply_blcks=`cat $lbu_tmpfile` ; lbu_blcks=$lbu_dsply_blcks
  408.             rm -f $lbu_tmpfile
  409.         fi
  410. }
  411.  
  412. # ******************************************************************
  413. # *                  Select compression method                     *
  414. # ******************************************************************
  415.  
  416. lbu_compress() {
  417.         dialog --title "Blocksize selection" \
  418.         --backtitle "$TVERSION"\
  419.         --menu "** REMEMBER to re-select DEVICE after changing compression mode **" 22 75 6     \
  420.         "gzip"       "Use a gzipped tar archive (default)    (ext = .tgz)"    \
  421.         "compress" "Use a compressed tar archive           (ext =.tar.Z)"     \
  422.         "none"     "Do not use any compression on archive  (ext = .tar)"     2> $lbu_tmpfile
  423.  
  424. # ------- Get the selection made and act accordingly
  425.  
  426.         if [ $? = 1 -o $? = 255 ]; then
  427.             rm $lbu_tmpfile
  428.             lbu_msgtyp="Informational" ; lbu_msgtxt="Operation cancelled."
  429.             lbu_hgt=5 ; lbu_wth=34
  430.             lbu_message
  431.         else
  432.  
  433.             lbu_dsply_cmprs=`cat $lbu_tmpfile`
  434.             if [ $lbu_dsply_cmprs = gzip ]; then lbu_orig_ext='.tgz'; lbu_cmprs=z ; fi
  435.             if [ $lbu_dsply_cmprs = compress ]; then lbu_orig_ext='.tar.Z' ; lbu_cmprs=Z ; fi
  436.             if [ $lbu_dsply_cmprs = none ]; then lbu_orig_ext='.tar' ; lbu_cmprs='' ;  fi
  437.             rm -f $lbu_tmpfile
  438.             if [ $lbu_dsply_multi = yes ]; then
  439.                 if [ $lbu_cmprs != "" ]; then 
  440.                     lbu_msgtyp="Informational"
  441.                     lbu_msgtxt="Cannot combine compressed format with\na Multi-volume archive. 'Multi' set to 'no'"
  442.                     lbu_hgt=6 ; lbu_wth=60
  443.                     lbu_message
  444.                     lbu_dsply_multi=no ; lbu_multi=""
  445.                 fi
  446.             fi
  447.             lbu_device="" ; lbu_dsply_dev=""
  448.             lbu_msgtyp="Informational" ; lbu_msgtxt="Compression mode changed.\nPLEASE BE SURE TO RE-SELECT DEVICE."
  449.             lbu_hgt=6 ; lbu_wth=40
  450.             lbu_message
  451.         fi
  452. }
  453.  
  454. # ***********************************************************************
  455. # *                       Start the backup process                      *
  456. # ***********************************************************************
  457.  
  458. lbu_begin() {
  459.     if [ -z "$lbu_device" ]; then
  460.         lbu_msgtyp="Error" ; lbu_msgtxt="Please enter a Device selection before\nstarting the Backup"
  461.         lbu_hgt=6 ; lbu_wth=45
  462.         lbu_message
  463.     else
  464.         if [ -z "$lbu_dirfil" ]; then
  465.             lbu_msgtyp="Error" ; lbu_msgtxt="Please enter a Dir/File selection before\nstarting the Backup"
  466.             lbu_hgt=6 ; lbu_wth=45
  467.             lbu_message
  468.         else
  469.             lbu_cxtd=c
  470.             lbu_buildcmd
  471. # --------- DO THE BACKUP !!!!!
  472.             lbu_status="BACKUP IN PROGRESS"
  473.             echo $lbu_status > $HOME/.lbu_last_backup
  474.             lbu_devexist=yes
  475.             if [ $lbu_dsply_multi = yes ]; then
  476.                 lbu_hlpfile=$lbu_dir/lbu_Minfo
  477.                 lbu_help
  478.                 clear
  479.                 lbu_status=`date`"\n\n========================== BACK-UP IN PROGRESS ============================\n"
  480.                 echo $lbu_status > $HOME/.lbu_last_backup
  481.                 echo "BACKUP STARTED : " `date` > $lbu_logfile
  482.                 eval $lbu_cmd_line | tee -a $lbu_logfile
  483.  
  484.                 if [ $? = 0 ]; then
  485.                     lbu_status=`date`"\n\n=================== BACK-UP COMPLETION STATUS: SUCCESS ======================\n"
  486.                 else
  487.                     lbu_status=`date`"\n\n=================== BACK-UP COMPLETION STATUS: FAILURE ======================\n"
  488.                 fi
  489.                 echo $lbu_status > $HOME/.lbu_last_backup
  490. #
  491. # ------- If required mail log to user
  492. #
  493.  
  494.                 if [ $lbu_mail = yes ]; then
  495.                     mail -s "L.B.U BACKUP LOG" $LOGNAME < $lbu_logfile
  496.                 fi
  497.  
  498.             else
  499.                 lbu_bkup_rest_comp=BACK-UP
  500.                 lbu_bldsh_bg
  501.                 exec $lbu_bkup_bg &
  502.  
  503.             fi
  504.  
  505.  
  506.         fi
  507.     fi
  508. }
  509.  
  510. # *********************************************************************
  511. # *              Build shellscript for background run                 *
  512. # *********************************************************************
  513.  
  514. lbu_bldsh_bg() {
  515.         echo "#!/bin/sh" > $lbu_bkup_bg
  516.         echo '' >> $lbu_bkup_bg
  517.         echo 'lbu_dir='$lbu_dir >> $lbu_bkup_bg
  518.         echo 'lbu_bkup_rest_comp='$lbu_bkup_rest_comp >> $lbu_bkup_bg
  519.         echo 'home='$HOME >> $lbu_bkup_bg
  520.         echo 'lbu_logfile='$lbu_logfile >> $lbu_bkup_bg
  521.         echo 'lbu_status=`date`"\n\n========================= $lbu_bkup_rest_comp IN PROGRESS ===========================\n"' >> $lbu_bkup_bg
  522.         echo 'echo $lbu_status > $HOME/.lbu_last_backup' >> $lbu_bkup_bg
  523.         echo 'echo $lbu_bkup_rest_comp STARTED : `date` > $lbu_logfile' >> $lbu_bkup_bg
  524.         echo "$lbu_cmd_line >> $lbu_logfile 2>&1" >> $lbu_bkup_bg
  525.         echo 'if [ $? = 0 ]; then' >> $lbu_bkup_bg
  526.         echo 'lbu_status=`date`"\n\n================= $lbu_bkup_rest_comp COMPLETION STATUS: SUCCESS ====================\n+++++++++++++++++ (Check the log-file for messages.) ++++++++++++++++++++\n"' >> $lbu_bkup_bg
  527.         echo 'else' >> $lbu_bkup_bg
  528.         echo 'lbu_status=`date`"\n\n================= $lbu_bkup_rest_comp COMPLETION STATUS: FAILURE ====================\n+++++++++++++++++ (Check the log-file for messages.) ++++++++++++++++++++\n"' >> $lbu_bkup_bg
  529.         echo 'fi' >> $lbu_bkup_bg
  530.         echo 'echo $lbu_status > $HOME/.lbu_last_backup' >> $lbu_bkup_bg
  531.         echo '' >> $lbu_bkup_bg
  532.         echo 'lbu_mail='$lbu_mail >> $lbu_bkup_bg
  533.         echo '' >> $lbu_bkup_bg
  534.         echo '#' >> $lbu_bkup_bg
  535.         echo '# ------- If required mail log to user' >> $lbu_bkup_bg
  536.         echo '#' >> $lbu_bkup_bg
  537.         echo '' >> $lbu_bkup_bg
  538.         echo 'if [ $lbu_mail = yes ]; then' >> $lbu_bkup_bg
  539.         echo '    mail -s "L.B.U $lbu_bkup_rest_comp LOG" $LOGNAME < $lbu_logfile' >> $lbu_bkup_bg
  540.         echo 'fi' >> $lbu_bkup_bg
  541.  
  542.         chmod 755 $lbu_bkup_bg
  543. }
  544.  
  545. # *********************************************************************
  546. # *                      Build the command line                       *
  547. # *********************************************************************
  548.  
  549. lbu_buildcmd() {
  550.     lbu_cmd_line="" ; echo $lbu_cmd_line > $lbu_logfile
  551.     lbu_cmd_line='tar '$lbu_multi' '$lbu_total' '$lbu_excl' '$lbu_owner' -b '$lbu_blcks' -'$lbu_cxtd$lbu_absol$lbu_vbose$lbu_perms$lbu_cmprs'f '$lbu_device' '$lbu_dirfil
  552. }
  553.  
  554. # **********************************************************************
  555. # *                         L.B.U Scheduling                           *
  556. # **********************************************************************
  557.  
  558. lbu_schedule() {
  559.  
  560.     case $LOGNAME in
  561.         root)    ;;
  562.         *)    
  563.             lbu_msgtyp="Error" ; lbu_msgtxt="Only the System Manager can set up\nschedules. This function is not\navailable to you."
  564.             lbu_hgt=7 ; lbu_wth=45
  565.             lbu_message
  566.             return
  567.             ;;
  568.     esac        
  569.  
  570.     if [ $lbu_dsply_multi = "yes" ]; then
  571.         lbu_msgtyp="Error" ; lbu_msgtxt="Multi-volume flag is set. Only\nforeground operations allowed."
  572.             lbu_hgt=6 ; lbu_wth=45
  573.             lbu_message
  574.         
  575.      else
  576.         lbu_loop2=1
  577.         while [ $lbu_loop2 = 1 ]; do
  578.         dialog --title "$lbu_title" --menu "\n            **** L.B.U Scheduling ****\n" 22 74 5 \
  579.         "Back"   "Schedule a backup for later."         \
  580.         "Rest"      "Schedule a restore for later."        \
  581.         "Clear"  "Remove a previous schedule."             \
  582.         "Help"    "Help regarding Scheduling"            \
  583.         "Done"    "Return to Main Menu."            2> $lbu_tmpfile
  584.  
  585. # ------- Get selection and act accordingly
  586.  
  587.         if [ $? = 1 -o $? = 255 ]; then
  588.             rm $lbu_tmpfile
  589.             lbu_msgtyp="Informational" ; lbu_msgtxt="Operation cancelled."
  590.             lbu_hgt=5 ; lbu_wth=34
  591.             lbu_message
  592.             lbu_loop2=0
  593.             return
  594.         fi
  595.  
  596.         lbu_sel=`cat $lbu_tmpfile`
  597.         rm -f $lbu_tmpfile
  598.         case $lbu_sel in
  599.             Back)     
  600.                     if [ -z "$lbu_device" ]; then
  601.                         lbu_msgtyp="Error" ; lbu_msgtxt="Please enter a Device selection before\nscheduling the Backup"
  602.                         lbu_hgt=6 ; lbu_wth=45
  603.                         lbu_message
  604.                     else
  605.                         if [ -z "$lbu_dirfil" ]; then
  606.                             lbu_msgtyp="Error" ; lbu_msgtxt="Please enter a Dir/File selection before\nscheduling the Backup"
  607.                             lbu_hgt=6 ; lbu_wth=45
  608.                             lbu_message
  609.                         else
  610.  
  611.                             lbu_cxtd=c
  612.                             lbu_bkup_rest_comp=BACK-UP
  613.                             lbu_schedl
  614.                         fi
  615.                     fi
  616.                     ;;
  617.  
  618.             Rest)    
  619.                     if [ $lbu_devexist = no ]; then
  620.                         lbu_msgtyp="Error" ; lbu_msgtxt="The restore device is not valid.\nPlease re-enter."
  621.                         lbu_hgt=6 ; lbu_wth=45
  622.                         lbu_message
  623.                     else
  624.                         if [ -z "$lbu_device" ]; then
  625.                             lbu_msgtyp="Error" ; lbu_msgtxt="Please enter a Device selection before\nscheduling the Restore."
  626.                             lbu_hgt=6 ; lbu_wth=45
  627.                             lbu_message
  628.                         else
  629.  
  630.                             lbu_cxtd=x
  631.                             lbu_bkup_rest_comp=RESTORE
  632.                             lbu_schedl
  633.                         fi
  634.                     fi
  635.                     ;;
  636.  
  637.             Clear)        lbu_delsch;;
  638.             Help)        lbu_hlpfile=$lbu_dir/lbu_help5
  639.                     lbu_help
  640.                     ;;
  641.             Done)        lbu_loop2=0
  642.                     ;;
  643.             *)        lbu_invent;;
  644.         esac
  645.         done
  646.     fi
  647. }
  648.  
  649. # **********************************************************************
  650. # *                       Set up a schedule                            *
  651. # **********************************************************************
  652.  
  653. lbu_schedl() {
  654. #
  655. # ------- look for atrun
  656. #
  657.     lbu_cronerr=0
  658.     if [ $LOGNAME = root ]; then
  659.         if [ ! -a /var/spool/cron/crontabs/root ]; then
  660.             lbu_msgtyp="Informational" ; lbu_msgtxt="A crontab file does not exist for $LOGNAME.\nOne will be created."
  661.             lbu_hgt=6 ; lbu_wth=50
  662.             lbu_message
  663.             mkdir /var 2> /dev/null
  664.             mkdir /var/spool 2> /dev/null
  665.             mkdir /var/spool/cron 2> /dev/null
  666.             mkdir /var/spool/cron/crontabs 2> /dev/null
  667.             touch /var/spool/cron/crontabs/$LOGNAME
  668.             if [ $LOGNAME=root ]; then
  669.                 echo "* * * * * * /usr/lib/atrun" >> /var/spool/cron/crontabs/$LOGNAME
  670.             fi
  671.         fi
  672.     fi
  673.     lbu_cdrun=`ps -ax | grep crond | wc -l`
  674.     if [ $lbu_cdrun -lt 2 ]; then
  675.         if [ $LOGNAME = root ]; then
  676.             lbu_msgtyp="Warning" ; lbu_msgtxt="The cron daemon (crond) is not running.\nAttempting to start."
  677.             lbu_hgt=6 ; lbu_wth=45
  678.             lbu_message
  679.             /usr/sbin/crond 2> /dev/null
  680.             if [ $? = 0 ]; then
  681.                 lbu_msgtyp="Status" ; lbu_msgtxt="Crond started."
  682.                 lbu_hgt=5 ; lbu_wth=25
  683.                 lbu_message
  684.             else
  685.                 lbu_msgtyp="Status" ; lbu_msgtxt="Crond FAILED to start.\Please start manually."
  686.                 lbu_hgt=7 ; lbu_wth=35
  687.                 lbu_message
  688.                 lbu_cronerr=1
  689.             fi
  690.         else
  691.             lbu_msgtyp="Warning" ; lbu_msgtxt="The cron daemon (crond) is not running.\nSCHEDULES CANNOT BE RUN.\nPlease contact your system manager."
  692.             lbu_hgt=7 ; lbu_wth=45
  693.             lbu_message
  694.             lbu_cronerr=1
  695.         fi    
  696.     fi
  697.  
  698. #
  699. # ------- get run date build the script to be run by using the at command
  700. #
  701.     if [ $lbu_cronerr = 0 ]; then
  702.         lbu_date
  703.         if [ ! -z "$lbu_date" ]; then
  704.             lbu_buildcmd
  705.             lbu_bldsh_bg
  706.             at -f $lbu_bkup_bg $lbu_hr$lbu_min $lbu_mth$lbu_day$lbu_yr >$lbu_tmpfile 2>&1
  707.             if [ $? = 0 ]; then
  708.                 lbu_jobno=`awk -F\  '{print $2}' < $lbu_tmpfile`
  709.                 lbu_status="SCHEDULED. Job : $lbu_jobno\n\n=========== SCHEDULED $lbu_bkup_rest_comp RUN-TIME IS $lbu_hr:$lbu_min on $lbu_day/$lbu_mth/$lbu_yr ==========="
  710.                 echo $lbu_status > $HOME/.lbu_last_backup
  711.                 lbu_msgtyp="Status" ; lbu_msgtxt="Job has been submitted for execution.\n\nJOB NUMBER IS : $lbu_jobno\n\nPlease make note of this number."
  712.                 lbu_hgt=9 ; lbu_wth=45
  713.                 lbu_message
  714.             else
  715.                 lbu_msgtyp="Status" ; lbu_msgtxt="Job **FAILED** to be submitted."
  716.                 lbu_hgt=5 ; lbu_wth=45
  717.                 lbu_message    
  718.             fi
  719.         fi
  720.     fi
  721. }
  722.  
  723. # **********************************************************************
  724. # *                         Delete a scheduled backup                  *
  725. # **********************************************************************
  726.  
  727. lbu_delsch() {
  728.  
  729.     lbu_loop3=1
  730.     while [ $lbu_loop3 = 1 ]; do
  731.         dialog --title "L.B.U DELETE Schedule" --inputbox "Enter job number (? for help)" 8 40 2> $lbu_tmpfile
  732.         lbu_jobno=`cat $lbu_tmpfile`
  733.         rm -f $lbu_tmpfile
  734.  
  735. # ------- check for no input provided
  736.  
  737.           if [ -z $lbu_jobno ]; then
  738.             lbu_msgtyp="Error" ; lbu_msgtxt="No job number specified\n        Aborting"
  739.             lbu_hgt=6 ; lbu_wth=30
  740.             lbu_message
  741.             lbu_loop3=0
  742.         else
  743.  
  744. # ------- asking for help ?
  745.  
  746.             if [ $lbu_jobno = ? ]; then
  747.                 lbu_hlpfile=$lbu_dir/lbu_help7
  748.                 lbu_help
  749.                 lbu_loop3=1
  750.             else
  751.                 if [ ! -a /var/spool/atjobs/$lbu_jobno ]; then
  752.                     lbu_msgtyp="Error" ; lbu_msgtxt="The specified job number does not exist.\nPlease re-enter."
  753.                     lbu_hgt=6 ;lbu_wth=50
  754.                     lbu_message
  755.                 else
  756.                     lbu_isval=`cat /var/spool/atjobs/$lbu_jobno | grep lbu | wc -l`
  757.                     if [ $lbu_isval = 0 ]; then
  758.                         lbu_msgtyp="Error" ; lbu_msgtxt="This does not appear to be an L.B.U schedule.\nPlease re-enter."
  759.                         lbu_hgt=6 ;lbu_wth=50
  760.                         lbu_message
  761.                      else
  762.                         atrm $lbu_jobno >/dev/null 2>&1
  763.                         lbu_status="SCHEDULE DELETED"
  764.                         echo $lbu_status > $HOME/.lbu_last_backup
  765.                         lbu_msgtyp="Informational" ; lbu_msgtxt="The schedule has been DELETED."
  766.                         lbu_hgt=5 ;lbu_wth=50
  767.                         lbu_message
  768.                         lbu_loop3=0
  769.                     fi
  770.                 fi
  771.             fi
  772.         fi
  773.     done
  774. }
  775.  
  776.  
  777. # **********************************************************************
  778. # *                         L.B.U Restore Backup                       *
  779. # **********************************************************************
  780.  
  781. lbu_restore() {
  782.     if [ $lbu_devexist = no ]; then
  783.          lbu_msgtyp="Error" ; lbu_msgtxt="The restore device is not valid.\nPlease re-enter."
  784.         lbu_hgt=6 ; lbu_wth=45
  785.         lbu_message
  786.     else
  787.         if [ -z "$lbu_device" ]; then
  788.             lbu_msgtyp="Error" ; lbu_msgtxt="Please enter a Device selection before\nstarting the Restore"
  789.             lbu_hgt=6 ; lbu_wth=45
  790.             lbu_message
  791.         else
  792.             if [ -z "$lbu_dirfil" ]; then
  793.                 lbu_msgtyp="Informational" ; lbu_msgtxt="No Dir/File specified. All will be restored."
  794.                 lbu_hgt=5 ; lbu_wth=50
  795.                 lbu_message
  796.             fi
  797.             lbu_cxtd=x
  798.             lbu_buildcmd
  799. # --------- DO THE RESTORE !!!!!
  800.             lbu_status="RESTORE IN PROGRESS"
  801.             echo $lbu_status > $HOME/.lbu_last_backup
  802.             if [ $lbu_dsply_multi = yes ]; then
  803.                 lbu_hlpfile=$lbu_dir/lbu_Minfo
  804.                 lbu_help
  805.                 clear
  806.                 lbu_status=`date`"\n\n====================== RESTORE IN PROGRESS =========================\n"
  807.                 echo $lbu_status > $HOME/.lbu_last_backup
  808.                 echo "RESTORE STARTED : " `date` > $lbu_logfile
  809.                 eval $lbu_cmd_line | tee -a $lbu_logfile
  810.  
  811.                 if [ $? = 0 ]; then
  812.                     lbu_status=`date`"\n\n================== RESTORE COMPLETION STATUS: SUCCESS ===================\n+++++++++++++++++ (Check the log-file for messages.) ++++++++++++++++++++\n"
  813.                 else
  814.                     lbu_status=`date`"\n\n================== RESTORE COMPLETION STATUS: FAILURE ===================\n+++++++++++++++++ (Check the log-file for messages.) ++++++++++++++++++++\n"
  815.                 fi
  816.                 echo $lbu_status > $HOME/.lbu_last_backup
  817. #
  818. # ------- If required mail log to user
  819. #
  820.  
  821.                 if [ $lbu_mail = yes ]; then
  822.                     echo DIR = $lbu_dir
  823.                     mail -s "L.B.U RESTORE LOG" $LOGNAME < $lbu_logfile
  824.                 fi
  825.  
  826.             else
  827.                 lbu_bkup_rest_comp=RESTORE
  828.                 lbu_bldsh_bg
  829.                 exec $lbu_bkup_bg &
  830.  
  831.             fi
  832.         fi
  833.     fi
  834. }
  835.  
  836.  
  837.  
  838. # **********************************************************************
  839. # *                          Show STATUS message                       *
  840. # **********************************************************************
  841.  
  842. lbu_look() {
  843.     if [ -f $HOME/.lbu_last_backup ]; then
  844.         lbu_lbu="$lbu_line\nLast L.B.U action / date                   : `cat $HOME/.lbu_last_backup`\n$lbu_line"
  845.     else
  846.         lbu_lbu="$lbu_line\n           No previous L.B.U backup has been performed\n$lbu_line"
  847.     fi
  848.  
  849.     lbu_pwd="Current directory                  : `pwd`"
  850.     lbu_dat="Current date                     : `date`"
  851.     dialog --title "$lbu_title" --msgbox "$lbu_author\n\n$lbu_line\n$lbu_pwd\n$lbu_dat\n$lbu_lbu" 21 79
  852. }
  853.  
  854. # **********************************************************************
  855. # *               Compare backup with file-system                      *
  856. # **********************************************************************
  857.  
  858. lbu_comp() {
  859.     if [ $lbu_devexist = no ]; then
  860.         lbu_msgtyp="Error" ; lbu_msgtxt="The compare device is not valid.\nPlease re-enter."
  861.         lbu_hgt=6 ; lbu_wth=45
  862.         lbu_message
  863.         return
  864.     fi
  865.  
  866.     if [ -z "$lbu_device" ]; then
  867.         lbu_msgtyp="Error" ; lbu_msgtxt="Please enter a Device selection before\nstarting the Backup"
  868.         lbu_hgt=6 ; lbu_wth=45
  869.         lbu_message
  870.     else
  871.         lbu_vbose_orig=$lbu_vbose
  872.         lbu_vbose='v'
  873.         lbu_cxtd=d
  874.         lbu_buildcmd
  875.         lbu_vbose=$lbu_vbose_orig
  876. # --------- DO THE COMPARE
  877.         lbu_status="COMPARE IN PROGRESS"
  878.         echo $lbu_status > $HOME/.lbu_last_backup
  879.         if [ $lbu_dsply_multi = yes ]; then
  880.             lbu_hlpfile=$lbu_dir/lbu_Cinfo
  881.             lbu_help
  882.             clear
  883.             lbu_status=`date`"\n\n======================= COMPARE IN PROGRESS =========================\n"
  884.             echo $lbu_status > $HOME/.lbu_last_backup
  885.             echo "COMPARE STARTED: " `date` > $lbu_logfile
  886.             eval $lbu_cmd_line | tee -a $lbu_logfile
  887.  
  888.             if [ $? = 0 ]; then
  889.                 lbu_status=`date`"\n\n================== COMPARE COMPLETION STATUS: SUCCESS =====================\n"
  890.             else
  891.                 lbu_status=`date`"\n\n================== COMPARE COMPLETION STATUS: FAILURE =====================\n"
  892.             fi
  893.             echo $lbu_status > $HOME/.lbu_last_backup
  894. #
  895. # ------- If required mail log to user
  896. #
  897.             if [ $lbu_mail = yes ]; then
  898.                 mail -s "L.B.U COMPARE LOG" $LOGNAME < $lbu_logfile
  899.             fi
  900.  
  901.         else
  902.             lbu_bkup_rest_comp=COMPARE
  903.             lbu_bldsh_bg
  904.             exec $lbu_bkup_bg &
  905.         fi
  906.  
  907.     fi
  908. }
  909.  
  910. # **********************************************************************
  911. # *              Backup log file inspection subroutine                 *
  912. # **********************************************************************
  913.  
  914. lbu_inspect() {
  915.     if [ ! -a $lbu_logfile ]; then
  916.         lbu_msgtyp="Error" ; lbu_msgtxt="There is no log file to view."
  917.         lbu_hgt=5 ; lbu_wth=40
  918.         lbu_message
  919.     else
  920.         dialog --title "Linux Backup Log Inspection" --textbox $lbu_logfile 21 77
  921.     fi
  922.     return 0
  923. }
  924.  
  925. # **********************************************************************
  926. # *               Backup file view subroutine                          *
  927. # **********************************************************************
  928.  
  929. lbu_view() {
  930.     if [ -z "$lbu_device" ]; then
  931.         lbu_msgtyp="Error" ; lbu_msgtxt="Please enter a Device selection before\nattempting a view operation"
  932.         lbu_hgt=6 ; lbu_wth=45
  933.         lbu_message
  934.     else
  935.         if [ $lbu_devexist = no ]; then
  936.             lbu_msgtyp="Error" ; lbu_msgtxt="The view device is not valid.\nPlease re-enter."
  937.             lbu_hgt=6 ; lbu_wth=45
  938.             lbu_message
  939.         else
  940.             lbu_cxtd=t
  941.             lbu_excl_orig=$lbu_excl
  942.             lbu_excl=''
  943.             lbu_buildcmd
  944.             lbu_excl=$lbu_excl_orig
  945.             clear
  946.             eval $lbu_cmd_line | more
  947.             echo ''
  948.             echo ''
  949.             echo "======================== Please press RETURN to continue ==================="
  950.             read lbu_null
  951.         fi
  952.     fi
  953. }
  954.  
  955. # **********************************************************************
  956. # *                      L.B.U Save Config Subroutine                  *
  957. # **********************************************************************
  958.  
  959. lbu_write() {
  960.     if [ -f $HOME/.lburc ]; then
  961.         rm $HOME/.lburc
  962.     fi
  963.  
  964.     lbu_quote='"'
  965.     echo "lbu_devtype=$lbu_quote"$lbu_devtype$lbu_quote > $HOME/.lburc
  966.     echo "lbu_dsply_dev=$lbu_quote"$lbu_dsply_dev$lbu_quote >>$HOME/.lburc
  967.     echo "lbu_ext=$lbu_quote"$lbu_ext$lbu_quote >>$HOME/.lburc
  968.     echo "lbu_orig_ext=$lbu_quote"$lbu_orig_ext$lbu_quote >>$HOME/.lburc
  969.     echo "lbu_device="$lbu_quote$lbu_device$lbu_quote >>$HOME/.lburc
  970.  
  971.     echo "lbu_dirfil="$lbu_quote$lbu_dirfil$lbu_quote >>$HOME/.lburc
  972.     echo "lbu_dsply_dfl="$lbu_quote$lbu_dsply_dfl$lbu_quote >>$HOME/.lburc
  973.     echo "lbu_multi="$lbu_quote$lbu_multi$lbu_quote >>$HOME/.lburc
  974.     echo "lbu_dsply_multi="$lbu_quote$lbu_dsply_multi$lbu_quote >>$HOME/.lburc
  975.     echo "lbu_absol="$lbu_quote$lbu_absol$lbu_quote >>$HOME/.lburc
  976.     echo "lbu_dsply_absol="$lbu_quote$lbu_dsply_absol$lbu_quote >>$HOME/.lburc
  977.     echo "lbu_mail="$lbu_quote$lbu_mail$lbu_quote >>$HOME/.lburc
  978.     echo "lbu_dsply_mail="$lbu_quote$lbu_dsply_mail$lbu_quote >>$HOME/.lburc
  979.     echo "lbu_blcks="$lbu_quote$lbu_blcks$lbu_quote >>$HOME/.lburc
  980.     echo "lbu_dsply_blcks="$lbu_quote$lbu_dsply_blcks$lbu_quote >>$HOME/.lburc
  981.     echo "lbu_perms="$lbu_quote$lbu_perms$lbu_quote >>$HOME/.lburc
  982.     echo "lbu_dsply_perms="$lbu_quote$lbu_dsply_perms$lbu_quote >>$HOME/.lburc
  983.     echo "lbu_owner="$lbu_quote$lbu_owner$lbu_quote >>$HOME/.lburc
  984.     echo "lbu_dsply_owner="$lbu_quote$lbu_dsply_owner$lbu_quote >>$HOME/.lburc
  985.     echo "lbu_total="$lbu_quote$lbu_total$lbu_quote >>$HOME/.lburc
  986.     echo "lbu_dsply_total="$lbu_quote$lbu_dsply_total$lbu_quote >>$HOME/.lburc
  987.     echo "lbu_vbose="$lbu_quote$lbu_vbose$lbu_quote >>$HOME/.lburc
  988.     echo "lbu_dsply_vbose="$lbu_quote$lbu_dsply_vbose$lbu_quote >>$HOME/.lburc
  989.     echo "lbu_cmprs="$lbu_quote$lbu_cmprs$lbu_quote >>$HOME/.lburc
  990.     echo "lbu_dsply_cmprs="$lbu_quote$lbu_dsply_cmprs$lbu_quote >>$HOME/.lburc
  991.     echo "lbu_excl="$lbu_quote$lbu_excl$lbu_quote >>$HOME/.lburc
  992.     echo "lbu_dsply_excl="$lbu_quote$lbu_dsply_excl$lbu_quote >>$HOME/.lburc
  993.     echo "==END==" >>$HOME/.lburc
  994.  
  995.     dialog --title "L.B.U Write config" --msgbox "Current configuration saved to\n$HOME.lburc" 6 35
  996. }
  997.  
  998. # **********************************************************************
  999. # *                    L.B.U Exclusion list subroutine                 *
  1000. # **********************************************************************
  1001.  
  1002. lbu_exclude() {
  1003.     lbu_hlpfile="$lbu_dir/lbu_help8"
  1004.     lbu_help
  1005.     lbu_editor=$EDITOR
  1006.     if [ -z $lbu_editor ]; then
  1007.         vi $HOME/.lbu_exclude
  1008.     else
  1009.         $lbu_editor $HOME/.lbu_exclude
  1010.     fi
  1011. }
  1012.         
  1013. # **********************************************************************
  1014. # *                    L.B.U Quit subroutine                           *
  1015. # **********************************************************************
  1016.  
  1017. lbu_quit() {
  1018.     exit
  1019. }
  1020.  
  1021. # ***********************************************************************
  1022. # *  Invalid Entry subroutine alias 'Bummer I missed THAT possibility'  *
  1023. # ***********************************************************************
  1024.  
  1025. lbu_invent() {
  1026.     dialog --title "L.B.U inv_ent subroutine" \
  1027.     --backtitle "$TVERSION"\
  1028.     --msgbox "Invalid Entry" 5 25
  1029.     return 0
  1030. }
  1031.  
  1032. # ************************************************************************
  1033. # *                Generlised L.B.U utility subroutines                  *
  1034. # ************************************************************************
  1035.  
  1036. #
  1037. # ------- General help display sub-routine
  1038. #
  1039.  
  1040. lbu_help() {
  1041.     dialog --title "Linux Backup Utility Help Screen" \
  1042.     --backtitle "$TVERSION"\
  1043.     --textbox "$lbu_hlpfile" 21 77
  1044. }
  1045.  
  1046. # ------- General error message sub-routine
  1047.  
  1048. lbu_message() {
  1049.     dialog --title "L.B.U $lbu_msgtyp message" \
  1050.     --backtitle "$TVERSION"\
  1051.     --msgbox "$lbu_msgtxt" $lbu_hgt $lbu_wth
  1052.     return 0
  1053. }
  1054.  
  1055. # **********************************************************************
  1056. # *               L.B.U Date entry/validation sub-routine              *
  1057. # **********************************************************************
  1058.  
  1059. lbu_date() {
  1060.     lbu_curdate
  1061.     lbu_loop3=1
  1062.     while [ $lbu_loop3 = 1 ]; do
  1063.         lbu_dterr=1
  1064.     dialog --title "L.B.U Time/Date" \
  1065.     --backtitle "$TVERSION"\
  1066.     --inputbox "Example:\nHH:MM DD Mn YYYY\n15:18 23 02 1995" 10 25 2>$lbu_tmpfile
  1067.     
  1068.         lbu_date=`cat $lbu_tmpfile`
  1069.     
  1070. # ------- check for no input provided
  1071.  
  1072.           if [ -z "$lbu_date" ]; then
  1073.             lbu_msgtyp="Error" ; lbu_msgtxt="No date has been specified\n        Aborting"
  1074.             lbu_hgt=6 ; lbu_wth=35
  1075.             lbu_message
  1076.             lbu_loop3=0
  1077.         else
  1078. #
  1079. # ------- asking for help ?
  1080. #
  1081.             if [ "$lbu_date" = "?" ]; then
  1082.                 lbu_hlpfile=$lbu_dir/lbu_help6
  1083.                 lbu_help
  1084.                 lbu_loop3=1
  1085.                 lbu_dterr=0
  1086.             else
  1087.                 lbu_ccnt=`echo $lbu_date | wc -c`
  1088.                 if [ $lbu_ccnt != 17 ]; then
  1089.                     lbu_msgtyp="Error" ; lbu_msgtxt="The date entered is invalid.\nPlease see the example or\nenter ? for help."
  1090.                     lbu_hgt=7 ; lbu_wth=35
  1091.                     lbu_message
  1092.                 else
  1093.                     lbu_hr=`echo $lbu_date  | cut -c1-2`
  1094.                     lbu_min=`echo $lbu_date | cut -c4-5`
  1095.                     lbu_day=`echo $lbu_date | cut -c7-8`
  1096.                     lbu_mth=`echo $lbu_date | cut -c10-11`
  1097.                     lbu_yr=`echo $lbu_date  | cut -c13-16`
  1098.                     lbu_now=`date +%Y%m%d%H%M`
  1099.                     lbu_reset=`date +%m%d%H%M%Y`
  1100.                     lbu_dval=$lbu_mth$lbu_day$lbu_hr$lbu_min$lbu_yr
  1101.                     lbu_dent=$lbu_yr$lbu_mth$lbu_day$lbu_hr$lbu_min
  1102.                     if [ $lbu_now -ge $lbu_dent ]; then
  1103.                         lbu_msgtyp="Error" ; lbu_msgtxt="The date/time has already passed.\nPlease re-enter."
  1104.                         lbu_hgt=6 ; lbu_wth=40
  1105.                         lbu_message
  1106.                     else
  1107.                         rm -f $lbu_tmpfile
  1108. #
  1109. # ------- date validation
  1110. #
  1111. # ------- use the date command to perform basic validation
  1112. #
  1113.                         date $lbu_dval >/dev/null 2>$lbu_tmpfile
  1114.                         date $lbu_reset >/dev/null 2>&1
  1115.                         if [ -s $lbu_tmpfile ]; then
  1116.                             lbu_msgtyp="Error" ; lbu_msgtxt="Date validation error. Date entered is invalid.\nPlease re-enter."
  1117.                             lbu_hgt=6 ; lbu_wth=50
  1118.                             lbu_message
  1119.                         else
  1120. #
  1121. # ------- use bc to check if leap year
  1122. #
  1123.                             echo $lbu_yr%4 > $lbu_tmpfile
  1124.                             lbu_lyr=`bc < $lbu_tmpfile`
  1125.                             if [ $lbu_lyr != 0 ]; then
  1126.                                 if [ $lbu_day -gt 28 ]; then
  1127.                                     lbu_msgtyp="Error" ; lbu_msgtxt="Date 1validation error. Date entered is invalid.\nPlease re-enter."
  1128.                                     lbu_hgt=6 ; lbu_wth=50
  1129.                                     lbu_message
  1130.                                 else        
  1131.                                     lbu_dterr=0
  1132.                                     lbu_loop3=0
  1133.                                 fi
  1134.                             else
  1135.                                 lbu_dterr=0
  1136.                                 lbu_loop3=0
  1137.                             fi
  1138.                         fi
  1139.                     fi
  1140.                 fi
  1141.             fi
  1142.         fi
  1143.     done
  1144.  
  1145. rm -f $lbu_tmpfile
  1146.  
  1147. }
  1148.  
  1149. # *************************************************************************
  1150. # *               Display the current date and time                       *
  1151. # *************************************************************************
  1152.  
  1153. lbu_curdate() {
  1154.     lbu_cdat=`date`
  1155.     lbu_msgtyp="Informational" ; lbu_msgtxt="The current date and time is :\n$lbu_cdat"
  1156.             lbu_hgt=6 ; lbu_wth=35
  1157.             lbu_message
  1158. }
  1159.  
  1160. # *************************************************************************
  1161. # *               Main body of the Linux Backup Utility              *
  1162. # *************************************************************************
  1163.  
  1164. lbu_1st_time=`ls -a $HOME | grep .lbu_ | wc -l`
  1165. if [ $lbu_1st_time = 0 ]; then
  1166.     dialog --title "Linux Backup Utility Introduction Screen" \
  1167.     --backtitle "$TVERSION"\
  1168.     --textbox "$lbu_dir/lbu_1stintro" 21 77
  1169. fi
  1170.  
  1171. lbu_line="-------------------------------------------------------------------------"
  1172. lbu_orig_term=$TERM
  1173. lbu_title="Linux Backup Utility v1.10"
  1174. lbu_author="   ( jwb@uvo.dec.com )                           Jonathan Warburton-Brown"
  1175. lbu_orig_ext=".tgz"
  1176. lbu_bkup_bg=$HOME/.lbu_bkup_bg
  1177. lbu_logfile=$HOME/.lbu_backup_log
  1178. lbu_redir=''
  1179. lbu_devexist=yes
  1180. lbu_dsply_multi=no    ; lbu_multi=''
  1181. lbu_dsply_absol=yes     ; lbu_absol='P'
  1182. lbu_dsply_mail=no    ; lbu_mail=no
  1183. lbu_dsply_blcks=20    ; lbu_blcks='20'
  1184. lbu_dsply_perms=yes    ; lbu_perms='p'
  1185. lbu_dsply_owner=yes    ; lbu_owner='--same-owner'
  1186. lbu_dsply_total=yes    ; lbu_total='--totals'
  1187. lbu_dsply_vbose=yes    ; lbu_vbose='v'
  1188. lbu_dsply_cmprs=gzip    ; lbu_cmprs='z'
  1189. lbu_dsply_excl=no    ; lbu_excl=''
  1190. #
  1191. # -------- Look for saved configuration details
  1192. #
  1193.  
  1194. # -------- Root only access ?
  1195.  
  1196. if [ $lbu_root_only = yes ]; then
  1197.     if [ $LOGNAME != root ]; then
  1198.         lbu_msgtyp="Error" ; lbu_msgtxt="\n Sorry but you must be\n 'root' to run backups"
  1199.         lbu_hgt=8 ; lbu_wth=30
  1200.         lbu_message
  1201.         TERM=$lbu_orig_term ; export TERM
  1202.         reset ; clear
  1203.         exit
  1204.     fi
  1205. fi    
  1206.     
  1207.  
  1208. #
  1209. # -------- Is another backup process running ?
  1210. #
  1211.  
  1212. lbu_inprg=`ps -ax | grep lbu | wc -l`
  1213. if [ $lbu_inprg != 3 ]; then
  1214.     lbu_msgtyp="Error" ; lbu_msgtxt="Another backup is running or the\nbackup script is being modified.\nPlease try again later."
  1215.     lbu_hgt=7 ; lbu_wth=40
  1216.     lbu_message
  1217.     reset ; clear
  1218.     exit
  1219. fi
  1220.  
  1221. #
  1222. # ------- if you change the name of LBU then you're on your own to
  1223. # ------- change the logo below !!!  ;-)
  1224. #
  1225.  
  1226. if [ -f $HOME/.lburc ]; then
  1227.  
  1228.     dialog --title "$lbu_title" --infobox "\n\n\n\
  1229.            _/_/              _/_/_/_/_/            _/_/    _/_/ \n\
  1230.           _/_/              _/_/    _/_/          _/_/    _/_/  \n\
  1231.          _/_/              _/_/    _/_/          _/_/    _/_/   \n\
  1232.         _/_/              _/_/_/_/_/            _/_/    _/_/    \n\
  1233.        _/_/              _/_/     _/_/         _/_/    _/_/     \n\
  1234.       _/_/       _/_/   _/_/     _/_/  _/_/   _/_/    _/_/      \n\
  1235.      _/_/_/_/_/  _/_/  _/_/_/_/_/_/    _/_/  _/_/_/_/_/_/       \n\n\
  1236.               ( Jonathan Warburton-Brown @ 1995 )\n\n\
  1237.      The Linux Backup Utility is now restoring its saved\n\
  1238.                      configuration details" 20 70
  1239.  
  1240.     lbu_reccnt=`wc -l < $HOME/.lburc`
  1241.     lbu_pcnt=`expr 100 / $lbu_reccnt`
  1242.     lbu_loop=1
  1243.     lbu_ctr=0
  1244.     while [ $lbu_loop = 1 ]; do
  1245.         lbu_ctr=`expr $lbu_ctr + 1`
  1246.         lbu_var=`cat $HOME/.lburc | head -n $lbu_ctr | tail -n 1`
  1247.         echo -ne `expr $lbu_pcnt \* $lbu_ctr`' %'\\b\\b\\b\\b\\b
  1248.         case $lbu_var in
  1249.             ==END==)    break;;
  1250.             *)        eval $lbu_var;;
  1251.         esac
  1252.     done
  1253.     loop=0
  1254.     echo -n '100 %'
  1255. fi
  1256.  
  1257. if [ -a $lbu_device ]; then
  1258.     lbu_devexist=yes
  1259. else
  1260.     lbu_devexist=no
  1261. fi
  1262.  
  1263. #
  1264. # ------- What is the latest status message ?
  1265. #
  1266.  
  1267. lbu_look
  1268.  
  1269. lbu_proceed
  1270. reset ; clear
  1271. exit
  1272.  
  1273. # ***********************************************************************
  1274. # *                         That's all Folks                            *
  1275. # ***********************************************************************
  1276.